package com.bpz.main.directive;

import com.bpz.jxw.link.model.Link;
import com.bpz.jxw.link.service.ILinkService;
import freemarker.core.Environment;
import freemarker.template.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 半瓶子 on 2/8/15.
 * blog: xusir.cnblogs.com
 */
public class FriendLinkDirective implements TemplateDirectiveModel {
    @Autowired
    ILinkService linkService;
    @Override
    public void execute(Environment env, Map map, TemplateModel[] templateModels, TemplateDirectiveBody body) throws TemplateException, IOException {
        if (body == null) {
            throw new TemplateModelException("null body");
        } else {
            Map<String,Object> condition=new HashMap<String, Object>();
            condition.put("status",1);
            List<Link> links=linkService.selectPage(condition,1,20);
           // BeansWrapper wrapper= new BeansWrapper(Configuration.VERSION_2_3_21);
            env.setVariable("links", env.getObjectWrapper().wrap(links));
            body.render(env.getOut());
        }
    }
}
